package com.example.demo.Service.Impl;

import com.example.demo.Service.BorrowService;
import com.example.demo.Service.LibrarianService;
import com.example.demo.mapper.BookMapper;
import com.example.demo.mapper.BorrowMapper;
import com.example.demo.mapper.LibrarianMapper;
import com.example.demo.model.Borrow;
import com.example.demo.model.Librarian;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BorrowServiceImpl implements BorrowService {

    @Autowired
    private BorrowMapper borrowMapper;


    @Override
    public Integer borrowBook(Borrow borrow){
        Integer status=borrowMapper.queryBookStatus(borrow.getBook_id());
        if(status==null){
            return -1;
        }
        else {
            if (status==1) {
                Integer result1 = borrowMapper.borrowBook(borrow);
                Integer result2 = borrowMapper.updateBookStatus(borrow.getBook_id());
                return result1 & result2;
            }else {
                return 0;
            }
        }


    }

    @Override
    public Integer returnBook(Borrow borrow) {
        Integer result1 = borrowMapper.returnBook(borrow);
//        System.out.println("还书结果"+result1);
        Integer result2 = borrowMapper.updateBookStatus(borrow.getBook_id());
//        System.out.println("更新书籍结果"+result2);
        return result1 & result2;
    }

    @Override
    public List<Borrow> getBorrowList() {

        List<Borrow> borrowList = borrowMapper.getBorrowList();
        return borrowList;
    }

    @Override
    public List<Borrow> getBorrowById(Integer reader_id) {
        List<Borrow> borrowList = borrowMapper.getBorrowById(reader_id);
        return borrowList;
    }

    @Override
    public Integer modifyBorrow(Borrow borrow) {
        Integer result = borrowMapper.modifyBorrow(borrow);
        return result;
    }


}
